package fudan.se.project.service.infrastructure.base;


import fudan.se.project.domain.User;
import fudan.se.project.repository.entity.conference.production.ReviewInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ReviewInfoPermissionService {

    private final ReviewInfoRepository reviewInfoRepository;

    private static final String AUTHOR = "AUTHOR";
    private static final String PCMEMBER = "PCMEMBER";

    @Autowired
    public ReviewInfoPermissionService(ReviewInfoRepository reviewInfoRepository) {
        this.reviewInfoRepository = reviewInfoRepository;
    }

    public boolean checkPermission(User user, String authority, long resourceId) {

        if (PCMEMBER.equals(authority)) {
            return null != reviewInfoRepository.findByReviewerAndReviewInfoId(user, resourceId);
        } else if (AUTHOR.equals(authority)) {
            return null != reviewInfoRepository.findByAuthorAndReviewInfoId(user, resourceId);
        }

        return false;
    }


}
